﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Hyt.Core;
using Hyt.Core.Security;
using Hyt.Passport.Models;

namespace Hyt.Passport.Persist
{
    public class PassportPrincipalResolver : ICustomPrincipalResolver
    {
        public  PassportPersistService PassportPersistService { get; set; } 

        public bool CanResolver(string customtype)
        {
            return customtype.ToLower() == typeof (Administrator).Name.ToLower();
        }

        public IPrincipal GetPrincipal(string customtype, string customprincipalid)
        {
            Guid id = Guid.Parse(customprincipalid);
            if (customtype.ToLower() == typeof (Administrator).Name.ToLower())
            {
                return PassportPersistService.GetQuery<Administrator>().FirstOrDefault(t => t.Id == id);
            }
            return Principal.Anonymous;
        }
    }
}
